#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>

#define SERVER_PORT 8080
#define MAX 80

int main(int argc, char **argv)
{
	struct sockaddr_in serveradd;
	int sockfd,n;
	char buf[MAX]={0};
	sockfd=socket(AF_INET,SOCK_STREAM,0);
	if(sockfd < 0)
		perror("socket create fail");
	char *str=argv[1];
	memset(&serveradd,0,sizeof(serveradd));
	serveradd.sin_family=AF_INET;
	serveradd.sin_port=htons(SERVER_PORT);
	serveradd.sin_addr.s_addr=inet_addr("127.0.0.1");
	if(connect(sockfd,(struct sockaddr *)&serveradd,sizeof(serveradd))<0)
		perror("connet fail");
	write(sockfd,str,strlen(str));
	n=read(sockfd,buf,MAX);
	printf("Server respond:\n");
	write(STDOUT_FILENO,buf,n);
	close(sockfd);
	return 0;
}
